home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / dnsconf / soa.c < prev    next >
C/C++ Source or Header  |  1996-07-27  |  3KB  |  107 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include "dnsconf.h"
  6. #include "internal.h"
  7. #include "../netconf/netconf.h"
  8.  
  9. PUBLIC RECORD_IN_SOA::RECORD_IN_SOA(const RECORD_PARSE &p)
  10.     : RECORD_IN(p,RTYPE_SOA)
  11. {
  12.     domain.setfrom (p.f1);
  13.     machine.setfrom (p.f2);
  14.     admin.setfrom (p.f3);
  15.     old_serial = new_serial = atol(p.f4);
  16.     refresh.setfrom (p.f5);
  17.     retry.setfrom (p.f6);
  18.     expire.setfrom (p.f7);
  19.     default_ttl.setfrom (p.f8);
  20. }
  21. /*
  22.     Create a SOA record with default values
  23. */
  24. PUBLIC RECORD_IN_SOA::RECORD_IN_SOA()
  25.     : RECORD_IN(RTYPE_SOA)
  26. {
  27.     THISHOST th;
  28.     const char *name = th.getname1();
  29.     domain.setfrom ("@");
  30.     machine.setfrom (name);
  31.     dns_cnv2abs (machine);
  32.     admin.setfrom ("hostmaster@");
  33.     admin.append (name);
  34.     dns_cnv2abs (admin);
  35.     old_serial = new_serial = 0;
  36.     update(NULL);
  37.     /* #Specification: SOA / default values
  38.         The following defaults are proposed the the user.
  39.         We can bet that he will use those. If you think
  40.         they are hazardous, please tell me.
  41.  
  42.  
  43.         refresh  = 60*60;
  44.         retry = 15*60;
  45.         expire = 14*24*60*60l;
  46.         default_ttl = 12*60*60;
  47.     */
  48.     refresh.setfrom (60*60);
  49.     retry.setfrom (15*60);
  50.     expire.setfrom (14*24*60*60l);
  51.     default_ttl.setfrom (12*60*60);
  52. }
  53.  
  54. PUBLIC void RECORD_IN_SOA::print (FILE *fout) const
  55. {
  56.     fprintf (fout,"%s\t%s\tIN\tSOA\t%s\t%s (\n"
  57.          "\t\t\t%ld ; serial\n"
  58.          "\t\t\t%ld ; refresh\n"
  59.          "\t\t\t%ld ; retry\n"
  60.          "\t\t\t%ld ; expire\n"
  61.          "\t\t\t%ld ; default_ttl\n"
  62.          "\t\t\t)\n"
  63.         ,domain.get(),ttlstr
  64.         ,machine.get()
  65.         ,admin.get()
  66.         ,new_serial
  67.         ,refresh.seconds,retry.seconds
  68.         ,expire.seconds,default_ttl.seconds);
  69. }
  70.  
  71. /*
  72.     Set the serial number to a new value (based on the current date)
  73. */
  74. PUBLIC void RECORD_IN_SOA::update(const char *name)
  75. {
  76.     long old = old_serial;
  77.     if (name != NULL){
  78.         long dns_serial = dns_getserial (name,"127.0.0.1",4);
  79.         if (dns_serial != -1) old = dns_serial;
  80.     }
  81.     if (new_serial == old){
  82.         /* #Specification: dnsconf / SOA / serial
  83.             The serial number of a SOA record is the date
  84.             it was modified and a revision number.
  85.             This gives a height digit number that always grows.
  86.             
  87.             The format is yymmddrr (where rr is a revision number).
  88.             
  89.             When updating a SOA serial, dnsconf use the current
  90.             date to setup a new serial number. If the new number
  91.             if smaller than the old, then the old one + 1 is
  92.             used instead. This makes sure the serial is always
  93.             growing.
  94.         */
  95.         time_t tt = time(NULL);
  96.         struct tm *t = localtime (&tt);
  97.         new_serial = t->tm_year*1000000+(t->tm_mon+1)*10000
  98.             + t->tm_mday * 100;
  99.         if (new_serial <= old){
  100.             new_serial = old+1;
  101.         }
  102.         setmodified();
  103.     }
  104. }
  105.     
  106.     
  107.